<template>

  <el-cascader
    :value="value"
    :options="options"
    :props="props"
    separator="-"
    @change="handleChange"
  />

</template>

<script>
import { queryListBytree } from '@/utils/index'

import { getDepartmentList } from '@/api/department'
export default {
  name: 'SelectTree',
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {

      options: [],
      props: {
        label: 'name',
        value: 'id'
      }
    }
  },
  async created() {
    this.options = queryListBytree(await getDepartmentList(), 0)
  },
  methods: {
    handleChange(value) {
      if (value.length > 0) {
        this.$emit('input', value[value.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
